package com.learn.chain;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import com.learn.chain.first.BossChain;
import com.learn.chain.first.CheckChain;
import com.learn.chain.first.Event;
import com.learn.chain.first.GroupChain;
import com.learn.chain.first.ManagerChain;
import com.learn.chain.second.Request;
import com.learn.chain.second.Response;
import com.learn.chain.second.interceptors.BridgeInterceptor;
import com.learn.chain.second.interceptors.CallServerInterceptor;
import com.learn.chain.second.interceptors.LogInterceptor;
import com.learn.chain.second.interceptors.NetworkInterceptor;
import com.learn.chain.second.OkClient;

public class MainActivity extends AppCompatActivity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        first();
        second();

    }

    public void first() {
        Event event = new Event();
        event.setDate(30);
        GroupChain groupChain = new GroupChain();
        new CheckChain.Builder()
                .addChecker(groupChain)
                .addChecker(new ManagerChain())
                .addChecker(new BossChain())
                .build();
        boolean result = groupChain.proceed(event);
        System.out.println("请假是否成功：" + result);
    }

    public void second() {
        OkClient client = new OkClient.Builder()
                .addInterceptor(new BridgeInterceptor())
                .addInterceptor(new NetworkInterceptor())
                .addInterceptor(new LogInterceptor())
                .addInterceptor(new CallServerInterceptor())
                .build();
        Request request = new Request.Builder()
                .url("http:123.com")
                .build();
        Response response = client.newCall(request).execute();
        System.out.println(response.toString());
    }

}
